<?php
 /******************************************************************************
 *   GunCMS is an avid supporter of open source software. This is the appropriate 
 *   option if you are creating an open source application with a license 
 *   compatible with the GNU GPL license v3.
 *   For details http://www.gnu.org/licenses/gpl.html
 *   DO NOT USE FOR COMMERCIAL WITHOUT PERMISSION
 *
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 ********************************************************************************/
/*
 * Created on 26-07-2008
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 class BWebshopPaymentMethodBean {
 	//constructor specials
 	public function __construct() {
 	}
 	/*
 	 * Validate Payment Method
     */
    function validatePayment() {
    	$msg = "";
    	if($_POST['payment_method'] == "") {
    		$msg = _("Payment name could not be empty"); 
    	}
		return $msg;
    }
       
	 /* Author	:
 	 * Desc		: Get all Payment Method from database
 	 * Param	:
 	 * 			@$db :
 	 * 			@PaymentMethod  :
 	 */ 
	   
 	function getAllPaymentMethod($db) {
		$strSQL = " SELECT * FROM ".TBL_PAYMENT_METHOD;
		$res = $db->get_results($strSQL);
		return $res;
	}
	
	
	/* Author	:
 	 * Desc		: Get Payment Method by id from database
 	 * Param	:
 	 * 			@$db :
 	 * 			@PaymentMethod  :
 	 */
	
	
	function getPaymentMethodById($db, $id) {
		$strSQL = "SELECT * FROM " . TBL_PAYMENT_METHOD . " WHERE id = '$id'";
		$res = $db->get_row($strSQL);
		return $res;
	}	
	
	
	
	/* Author	:
 	 * Desc		: Save array payment to database
 	 * Param	:
 	 * 			@$db :
 	 * 			@PaymentMethod  :
 	 */
	function savePayment($db,$payment) {
    	$sql=sprintf(
					"INSERT INTO %s(payment_method,payment_logo,description) " .
					"VALUES('%s','%s','%s')",
    				TBL_PAYMENT_METHOD, 
    				$payment['payment_method'],
					$payment['payment_logo'],
    				$payment['description']);  
        		
    	$res = $db->query($sql);
    	
    	if($res == true)
    		return $db->insert_id;
    	else
    		return -1;
    	
    }
	
	/* Author	:
 	 * Desc		: Update array Payment Method to database
 	 * Param	:
 	 * 			@$db :
 	 * 			@PaymentMethod  :
 	 */
	function updatePaymentMethod($db,$payment) {
    	$sql = sprintf("UPDATE  %s SET payment_method = '%s'," .
						" payment_logo = '%s'," .
    					" description = '%s'" .
    					" WHERE id = '%s'", 
					TBL_PAYMENT_METHOD,
					$payment['payment_method'], 
					$payment['payment_logo'], 
					$payment['description'], 
					$payment['id']);
		$res = $db->query($sql);
    	return $res;
    }
 	/* Author	:
 	 * Desc		: Delete Payment Method items based on $id
 	 * Param	:
 	 * 			@$db :
 	 * 			@id  :
 	 */
 	function deletePaymentMethod($db, $id) {
    	$sql = sprintf("DELETE FROM %1\$s" .
				" where %1\$s.id = '$id'", 
				TBL_PAYMENT_METHOD);
		
    	$res = $db->query($sql);
    	return $res;
    }
	
  
 	
 } 
?>
